define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order1/index' + location.search,
                    add_url: 'order1/add',
                    edit_url: 'order1/edit',
                    // del_url: 'order/del',
                    multi_url: 'order1/multi',
                    import_url: 'order1/import',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'supplier.suppname', title: __('Supplier.suppname'), operate: 'LIKE'},
                        {field: 'ordernum', title: __('Ordernum'), operate: 'LIKE'},
                        {field: 'paycode', title: __('Paycode'), operate: 'LIKE'},
                        {field: 'orderpaytype', title: __('Orderpaytype'), searchList: {"1":__('Orderpaytype 1'),"2":__('Orderpaytype 2')}, formatter: Table.api.formatter.normal},
                        {field: 'price', title: __('Price'), operate:false},
                        {field: 'freight', title: __('Freight'), operate:false},
                        {field: 'dikou', title: __('Dikou'), operate:false},
                        {field: 'coupon', title: __('Coupon'), operate:false},
                        {field: 'allprice', title: __('Allprice'), operate:false},
                        {field: 'userhome.nickname', title: __('Userhome.nickname'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'),"9":__('Status 9')}, formatter: Table.api.formatter.status},
                        {field: 'is_activity', title: __('Is_activity'), searchList: {"0":__('Is_activity 0'),"1":__('Is_activity 1')}, formatter: Table.api.formatter.normal},
                        {field: 'paytype', title: __('Paytype'), searchList: {"1":__('Paytype 1'),"2":__('Paytype 2'),"3":__('Paytype 3')}, formatter: Table.api.formatter.normal},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'is_check', title: __('Is_check'), searchList: {"0":__('Is_check 0'),"1":__('Is_check 1'),"2":__('Is_check 2')}, formatter: Table.api.formatter.normal},



                        // {field: 'is_yc', title: __('Is_yc'), searchList: {"1":__('Is_yc 1'),"0":__('Is_yc 0')}, formatter: Table.api.formatter.normal},




                        //{field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        //{field: 'address', title: __('Address'), operate: 'LIKE'},
                        //{field: 'fahuotime', title: __('Fahuotime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'shouhuotime', title: __('Shouhuotime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'wuliu_num', title: __('Wuliu_num'), operate: 'LIKE'},
                        // {field: 'wuliu_code', title: __('Wuliu_code'), operate: 'LIKE'},
                        //{field: 'wuliu_name', title: __('Wuliu_name'), operate: 'LIKE'},
                        //{field: 'tx_fahuo', title: __('Tx_fahuo'), operate:false},
                        // {field: 'invoice_id', title: __('Invoice_id')},
                        //{field: 'id', title: __('查看详情'), formatter: Controller.api.formatter.id,operate:false},
                        //{field: 'is_shouhou', title: __('Is_shouhou'), searchList: {"0":__('Is_shouhou 0'),"1":__('Is_shouhou 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'is_kaipiao', title: __('Is_kaipiao'), searchList: {"0":__('Is_kaipiao 0'),"1":__('Is_kaipiao 1'),"2":__('Is_kaipiao 2')}, formatter: Table.api.formatter.normal},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [

                                {
                                    name: 'detail',
                                    title: __('查看商品'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'order1/detail'
                                }
                            ]

                        }
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        
        delivery: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});